layui.config({
	base : "js/"
}).use(['form','layer','jquery','laydate','tree'],function(){
	var form = layui.form(),
		layer = parent.layer === undefined ? layui.layer : parent.layer,
		laypage = layui.laypage,
		laydate = layui.laydate,
		laytree = layui.tree,
		$ = layui.jquery;

	//解决layui低版本，switch开关关闭不能传值到后台的bug
	form.on('switch', function(data) {
		$(data.elem).attr('type', 'hidden').val(this.checked ? true : false);
	});

	form.on("submit(add)",function(data){
		//弹出loading
		var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
		$.ajax({
			url:"/role/insert.do",
			data:data.field,
			type:"post",
			success:function(data){
				top.layer.close(index);
				top.layer.msg("保存成功！");
				layer.closeAll("iframe");
				//刷新父页面
				parent.location.reload();
				return true;
		    },
			error:function(){
				top.layer.close(index);
				top.layer.msg("添加成功！");
				layer.closeAll("iframe");
				//刷新父页面
				parent.location.reload();
				return false;
			}
		})

	})

})
